package ird.demo.common;

public class HotkeyUtil {
	private static String getBtn(String btnName, String hotKey, String label, String onclick){
		StringBuilder sb = new StringBuilder();
		sb.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" name=\""+btnName+"\" id=\""+btnName+"\" onclick=\""+onclick+"\">");
		if(hotKey != null){
			sb.append(hotKey+":");
		}
		sb.append(label+"</a>");
		
		if(hotKey != null){
			String jsHotKey = hotKey.toLowerCase();
			if("enter".equals(jsHotKey)){
				jsHotKey = "return";
			}
			sb.append("<script type='text/javascript'>");
			sb.append("$(document).bind('keydown', '"+jsHotKey+"', function(){ $('#"+btnName+"').trigger('click')});");
			sb.append("</script>");
		}
		return sb.toString();
	}
	
	public static String getLogoutBtn(){
		return getBtn("logout_btn", "F3", "Logout", "exit()");
	}
	
	public static String getPrintBtn(){
		return getBtn("print_btn", "Esc", "Print", "window.print()");
	}
	
	public static String getGoMainMenuBtn(String contextPath){
		return getBtn("f3_mainMenu_btn", "F3", "Exit", "window.location.href ='"+contextPath+"/mainMenu'");
	}
	
	public static String getGoSubMenuBtn(String menuId,String menuDesc, String contextPath){
		return getBtn("f3_subMenu_btn", "F3", "Exit", "window.location.href ='"+contextPath+"/subMenu?menuId="+menuId+"&menuDesc="+menuDesc+"'");
	}
	
	public static String getGoNewTcBtn(String tranId,String tranDesc, String contextPath){
		return getBtn("f1_btn", "F1", "New", "window.location.href ='"+contextPath+"/transaction/"+tranId+"/input?tranDesc="+tranDesc+"'");
	}
	
	public static String getEnterBtn(){
		return getBtn("enter_btn", "Enter", "Input", "submitForm($('#ff'))");
	}
	
	public static String getUpdBtn(){
		return getBtn("f8_btn", "F8", "Update", "validateAndSubmitForm($('#ff'))");
	}
	
	public static String getGoFstScreenBtn(String tranId,String tranDesc, String contextPath){
		return getBtn("f12_btn", "F12", "First Screen", "window.location.href ='"+contextPath+"/transaction/"+tranId+"/input?keepKeyParamInd=Y&tranDesc="+tranDesc+"'");
	}
}
